package fourth_assignment;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.LinkedList;

import second_assignment.Consts_2nd;

public class MainApp_4th {
	
	@SuppressWarnings("unchecked")
    public static void main(String[] args) 
	{ 
		StaticDynamicSimulator simulator = new StaticDynamicSimulator();

		simulator.StaticDynamicInit();	

		int[] clientResults = new int[3];
		int totalClients = 0;
		int totalRejected = 0;
		int totalCost = 0;
        System.out.println("Lambda = " + Consts_2nd.Lambda + ", Parameter d = " + Consts_4th.MAX_FAILURES);
		for (int i = 1; i <= 7; ++i){
			LinkedList<Request> requestList = null;
			int currCost = 0;
			
			//This code was used to load the requests
			//objects from a file (serialization)
			FileInputStream fis = null;
			String filename = "requests" + i;
			ObjectInputStream in = null;
			try
			{
				fis = new FileInputStream(filename);
			    in = new ObjectInputStream(fis);
			    requestList = (LinkedList<Request>)in.readObject();
			    in.close();
			}
			catch(IOException ex)
			{
				ex.printStackTrace();
			}
			catch(ClassNotFoundException ex)
			{
				ex.printStackTrace();
			}	
			
	    	System.out.println("Day " + i);
	    	
        	// RUN A DAY'S SIMULATION
        	clientResults = simulator.ClientsManagment24(requestList);
        	totalClients += clientResults[0];
            totalRejected += clientResults[1];
            currCost = clientResults[2];
            
            System.gc();
            
            currCost += simulator.NewDay(i);
            System.out.println("Total cost of DYNAMIC ALGORITHM today is: " + currCost);
            totalCost += currCost;
		}
		System.out.println("**********************************************************************");
		System.out.println("Total rejected clients percentage is: " + ((double)totalRejected/((double)totalClients))*100);
		
	  }
}
